﻿namespace ACCOUNTING
{
    using System;
    using System.Collections;
    using System.Data.OleDb;

    public sealed class OleDBHelperParameterCache
    {
        private static Hashtable paramCache = Hashtable.Synchronized(new Hashtable());

        private OleDBHelperParameterCache()
        {
        }

        public static void CacheParameterSet(string connectionString, string commandText, params OleDbParameter[] commandParameters)
        {
            if ((connectionString == null) || (connectionString.Length == 0))
            {
                throw new ArgumentNullException("connectionString");
            }
            if ((commandText == null) || (commandText.Length == 0))
            {
                throw new ArgumentNullException("commandText");
            }
            string str = connectionString + ":" + commandText;
            paramCache[str] = commandParameters;
        }

        private static OleDbParameter[] CloneParameters(OleDbParameter[] originalParameters)
        {
            int num2 = originalParameters.Length - 1;
            OleDbParameter[] parameterArray = new OleDbParameter[num2 + 1];
            int num3 = num2;
            for (int i = 0; i <= num3; i++)
            {
                parameterArray[i] = (OleDbParameter) ((ICloneable) originalParameters[i]).Clone();
            }
            return parameterArray;
        }

        public static OleDbParameter[] GetCachedParameterSet(string connectionString, string commandText)
        {
            if ((connectionString == null) || (connectionString.Length == 0))
            {
                throw new ArgumentNullException("connectionString");
            }
            if ((commandText == null) || (commandText.Length == 0))
            {
                throw new ArgumentNullException("commandText");
            }
            string str = connectionString + ":" + commandText;
            OleDbParameter[] originalParameters = (OleDbParameter[]) paramCache[str];
            if (originalParameters == null)
            {
                return null;
            }
            return CloneParameters(originalParameters);
        }
    }
}

